package com.bingo.generate.comm.util;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

/**
 * ClassName
 * Description
 * Create by lc
 * Date 2021/11/3 15:46
 */
public class DosUtil {

    public static List<String> runDos(String... shStrArr)  {
        List list=new ArrayList();
        String shStr=null;
        if (shStrArr.length==1){
            shStr=shStrArr[0];
        }
        try {
            Process p = Runtime.getRuntime().exec(shStr);
            InputStream is = p.getInputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(is));
            String line;
            while((line = reader.readLine())!= null){
                //System.out.println(line);
//                System.out.println(line);
                list.add(line);
            }
            p.waitFor();
            is.close();
            reader.close();
            p.destroy();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return list;
    }

    public static String runDos2(String... shStrArr)  {
        List<String> list=runDos(shStrArr);
        StringBuilder strBud=new StringBuilder();
        for (String s : list) {
            strBud.append(s) .append("\n") ;
        }
        String str=strBud.toString();
        try {
            System.out.println(new String(str.getBytes("utf-8")));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return str;
    }

}
